package com.hnas.core.util;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ServiceDataUtil {
	
	private static ObjectMapper mapper = new ObjectMapper();

	

	/**
	 * 组装返回数据
	 * 
	 * @param resultCode
	 *            返回码
	 * @param resultMsg
	 *            返回信息
	 * @param date
	 *            返回数据
	 * @return 组装好的数据结构
	 * @throws JsonProcessingException 
	 */
	@SuppressWarnings("all")
	public static String getReturnDate(String resultCode, String resultMsg,Object data) throws JsonProcessingException {
		Map<String, Object> m = new HashMap<String, Object>();
		m.put("resultCode", resultCode);
		m.put("resultMsg", resultMsg);
		m.put("resultData", mapper.writeValueAsString(data));
		return mapper.writeValueAsString(m);
	}

	/**
	 * 返回错误数据
	 * 
	 * @param resultCode
	 * @param resultMsg
	 * @return
	 */
	public static String errorReturnDate(String resultCode, String resultMsg) {
		try {
			return getReturnDate(resultCode, resultMsg, null);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return null;
	}
}
